import 'package:dio/dio.dart';
/*class DioRendingView extends StatefulWidget {
  const DioRendingView({super.key});

  @override
  State<DioRendingView> createState() => _DioRendingViewState();
}

class _DioRendingViewState extends State<DioRendingView> {
  @override
  Widget build(BuildContext context) {
    return const Placeholder();
  }
}*/

import 'package:flutter/material.dart';

class DioFutureRendingView extends StatefulWidget {
  const DioFutureRendingView({super.key});
  @override
  State<DioFutureRendingView> createState() => _MessagePageState();
}

class _MessagePageState extends State<DioFutureRendingView> {
  _getCateList() async {
    var response = await Dio().get("https://jdmall.itying.com/api/pcate");
    print('response:$response');
    return response.data["result"];
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('FutureRending Viuew'),
        ),
        body: FutureBuilder(
            future: _getCateList(),
            builder: (context, snapshot) {
              if (snapshot.connectionState == ConnectionState.done) {
                if (snapshot.hasError) {
                  return Center(child: Text("Error:${snapshot.error}"));
                } else {
                  var response = snapshot.data as List;
                  return ListView(
                    children: response.map((value) {
                      return ListTile(
                        title: Text("${value["title"]}"),
                      );
                    }).toList(),
                  );
                }
              } else {
                return const Center(child: CircularProgressIndicator());
              }
            }));
  }
}
